<?php
namespace app\api\model;
use think\Model;
use app\api\model\TeamIncome as TeamIncomeModel;
use app\api\model\Single as SingleModel;
class Receivables extends Model{
    protected $type = [
        
    ];
    public function receipts(){
        return $this->hasMany('Receipt','income_id','id');
    } 
    public function allList(){
        $is_zero=0;
        $teamIncomeModel = new TeamIncomeModel();
        $datas1 = $teamIncomeModel->with(['team','receipts']) ->order('id desc')->select();
        $singleModel = new SingleModel();
        $datas2 = $singleModel->order('id desc') ->select();
        $datas3 = array_merge($datas1,$datas2) ;

        foreach($datas3 as $key => $val){     
            $money=0;     
            $total=0;            
            foreach($val['receipts'] as $key2 =>$val2){
                $money += $val2['money'];
            }
           $total = $val['sell_price'] * $val['num'];
           if($is_zero=="true" && $total - $money == 0){
            array_splice($datas3, $key, 1);
           }
        }

        return $datas3;
    }

}